import { Controller, Get, Query, Post, Body, Put, Param, Delete, UseGuards, UsePipes, UseInterceptors, UploadedFiles, UploadedFile } from '@nestjs/common';
import { UserEntity } from 'src/entities/user.entity';
import { BasicGuard } from 'src/app.basic.guard';
import { UserService } from 'src/services/user.service';
import { TokenGuard } from 'src/app.token.guard';
import { UserInfo } from 'src/decorators/user.decorator';
import { UserToken } from 'src/entities/user.token';
import { AnyFilesInterceptor, FileInterceptor } from '@nestjs/platform-express';

@Controller('user')
@UseGuards(BasicGuard)
export class UserController {
    constructor(private readonly userService: UserService){}

    @Post("login")
    async doLogin(@Body() user: UserEntity){
        return await this.userService.doLogin(user.mobileNo, user.password);
    }

    @Get("info")
    @UseGuards(TokenGuard)
    async getUser(@UserInfo() userInfo: UserToken){
        return {
            a: 22
        }
    }

    @Post('upload')
    @UseInterceptors(FileInterceptor('file'))
    uploadFile(@UploadedFile() files: Express.Multer.File) {
        console.log(files);
    }
}